home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / ZSI / twisted / interfaces.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  93 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import sys
  5. import warnings
  6. from zope.interface import classProvides, implements, Interface
  7. from ZSI import EvaluateException, ParseException, ParsedSoap, SoapWriter
  8.  
  9. def CheckInputArgs(*interfaces):
  10.     l = len(interfaces)
  11.     
  12.     def wrapper(func):
  13.         
  14.         def check_args(self, *args, **kw):
  15.             for i in range(len(args)):
  16.                 if l > i or interfaces[i].providedBy(args[i]) or interfaces[-1].providedBy(args[i]):
  17.                     continue
  18.                 
  19.                 if l > i:
  20.                     raise TypeError, 'arg %s does not implement %s' % (args[i], interfaces[i])
  21.                 
  22.                 raise TypeError, 'arg %s does not implement %s' % (args[i], interfaces[-1])
  23.             
  24.             func(self, *args, **kw)
  25.  
  26.         return check_args
  27.  
  28.     return wrapper
  29.  
  30.  
  31. class HandlerChainInterface(Interface):
  32.     
  33.     def processRequest(self, input, **kw):
  34.         pass
  35.  
  36.     
  37.     def processResponse(self, output, **kw):
  38.         pass
  39.  
  40.  
  41.  
  42. class CallbackChainInterface(Interface):
  43.     
  44.     def processRequest(self, input, **kw):
  45.         pass
  46.  
  47.  
  48.  
  49. class DataHandler:
  50.     classProvides(HandlerChainInterface)
  51.     readerClass = None
  52.     writerClass = None
  53.     
  54.     def processRequest(cls, input, **kw):
  55.         return ParsedSoap(input, readerclass = cls.readerClass)
  56.  
  57.     processRequest = classmethod(processRequest)
  58.     
  59.     def processResponse(cls, output, **kw):
  60.         sw = SoapWriter(outputclass = cls.writerClass)
  61.         sw.serialize(output)
  62.         return sw
  63.  
  64.     processResponse = classmethod(processResponse)
  65.  
  66.  
  67. class DefaultHandlerChain:
  68.     
  69.     def __init__(self, cb, *handlers):
  70.         self.handlercb = cb
  71.         self.handlers = handlers
  72.  
  73.     __init__ = CheckInputArgs(CallbackChainInterface, HandlerChainInterface)(__init__)
  74.     
  75.     def processRequest(self, arg, **kw):
  76.         for h in self.handlers:
  77.             arg = h.processRequest(arg, **kw)
  78.         
  79.         return self.handlercb.processRequest(arg, **kw)
  80.  
  81.     
  82.     def processResponse(self, arg, **kw):
  83.         if arg is None:
  84.             return None
  85.         
  86.         for h in self.handlers:
  87.             arg = h.processResponse(arg, **kw)
  88.         
  89.         s = str(arg)
  90.         return s
  91.  
  92.  
  93.